﻿package rob.entity{
	import flash.display.Sprite;
	import rob.core.Primitive3d;
	import rob.core.Camera3d;
	import rob.maths.VertexMaths;
	import rob.data.Vert3d;
	
	// ground contains flat ground meshes, no need to redraw
	// instead model as a single point & scale (correctly) when zooming
	
	public class Ground extends Primitive3d{
		private var _container:Sprite;
		private var _floor:Array;
		private var _camera:Camera3d;
	
		public function Ground():void{
			_container = new Sprite();
			//_container.cacheAsBitmap = true;
			_floor = [];
		}

		// we just move the container to update
		public function update():void{
			var p:Vert3d = position;
			VertexMaths.project(p,_camera);
			_container.x = p.sx;
			_container.y = p.sy;
		}
		
		public function addFloor(f:Floor):void{ 
			_floor.push(f);
			_container.addChild(f);
		}
		
		public function set camera(c:Camera3d):void{_camera = c;}
		
		public function get floor():Array{ return _floor; }
		public function get container():Sprite{ return _container; }
	}
}